<template>
    <a-select v-model:value="modelValue" :placeholder="'请选择' + formItem.label" allowClear v-on="formItem.eventObject" v-bind="formItem.props">
        <template v-for="option in formItem.options" :key="option.value">
            <a-select-option :value="option.value">
                {{ option.label }}
            </a-select-option>
        </template>
    </a-select>
</template>
<script lang="ts">
import { defineComponent, PropType, computed } from 'vue'
import { Select } from 'ant-design-vue'

export default defineComponent({
    name: 'SchemaFormSelect',
    components: {
        [Select.name]: Select,
        [Select.Option.displayName]: Select.Option
    },
    emits: ['update:value'],
    props: {
        formItem: {
            // 表单项
            type: Object as PropType<FormItem>,
            default: () => ({})
        },
        value: undefined as any // 表单项值
    },
    setup(props, { attrs, emit }) {
        const modelValue = computed({
            get: () => props.value,
            set: (val) => emit('update:value', val)
        })

        return {
            modelValue
        }
    }
})
</script>
